package com.dd.ent.car.common.http;
import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * 统一管理volley
 * Created by aqu-spring on 16/8/5.
 */
public class VolleyManager {

    private static VolleyManager volleyManager;
    // 建立请求队列
    private static RequestQueue queue;

    private VolleyManager(Context context) {
        queue = Volley.newRequestQueue(context);
    }


    public static VolleyManager instance(Context context) {
        if (volleyManager == null) {
            synchronized (VolleyManager.class) {
                if (volleyManager == null) {
                    volleyManager = new VolleyManager(context);
                }
            }
        }
        return volleyManager;
    }

    /**
     * 初始化volley
     *
     * @param context
     */
    public static void init(Context context) {
        instance(context);
    }


    public void addRequest(Request request){
        if (queue != null) {
            queue.add(request);
        }
    }

    public RequestQueue getQueue(){
        return queue;
    }
}
